package com.ux.iot.jetlinks.exception;

import com.ux.iot.core.exception.IotMsgServiceException;
import com.ux.iot.jetlinks.message.ErrorCode;
import lombok.Getter;

public class DeviceOperationException extends IotMsgServiceException {

    @Getter
    private final ErrorCode code;

    private final String message;

    public DeviceOperationException(ErrorCode errorCode) {
        this(errorCode, errorCode.getText());
    }

    public DeviceOperationException(ErrorCode errorCode, Throwable cause) {
        super(errorCode.getText());
        this.code = errorCode;
        this.message = cause.getMessage();
    }

    public DeviceOperationException(ErrorCode code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    @Override
    public String getMessage() {
        return message == null ? code.getText() : message;
    }


}
